define(["jquery","comm/form/form.comm"],function($,$comm){
	var quest = {};

	/**
	 * 数据处理(若不需要数据处理，可以不写)
	 */
    quest.formatData = function(obj){
    	if( obj.list && $.isArray(obj.list) && obj.list.length > 0 ){
    		for(var i = 0; i < obj.list.length; i++){
    			if( typeof obj.list[i] == "string" ){
    				var str = obj.list[i];
    				obj.list[i] = {};
    				obj.list[i].key = str;
    				obj.list[i].text = str;
    			}
    		}
    	}
		return obj;
	}

	/**
	 * tpl模板
	 */
	quest.tpl = function(){
		return 	'<script id="tpl_question_radio" type="text/html">'+
				'	<div {{if relationId}}relationId="{{relationId}}"{{/if}} class="qaCard form-group form-group-sm col-sm-{{length}} col-md-{{length}} grid-label-{{labelLength}}">'+
				'		<label class="control-label {{align}}">{{label}}</label>'+
				'		{{if status=="default"}}'+
				'   		<div class="control-input radio">'+
				'				{{each list as item i}}'+
				'					<label class="radio-inline">'+
				'						<input type="radio" class="validatebox" name="{{name}}" value="{{item.key}}" data-type="{{type}}" data-quesId="{{id}}" data-innDeCode="{{innDeCode}}" data-deCode="{{deCode}}" data-dataUnit="{{dataUnit}}" data-validate="{{validate}}" data-attention="{{attention}}">'+
				'						{{item.text}}'+
				'					</label>'+
				'				{{/each}}'+
				'   		</div>'+
				'		{{else if status=="readonly"}}'+	
				'   		<div class="control-input radio disabled">'+
				'				{{each list as item i}}'+
				'					<label class="radio-inline">'+
				'						<input type="radio" class="validatebox" name="{{name}}" value="{{item.key}}" data-type="{{type}}" data-quesId="{{id}}" data-innDeCode="{{innDeCode}}" data-deCode="{{deCode}}" data-dataUnit="{{dataUnit}}" data-validate="{{validate}}" data-attention="{{attention}}" disabled>'+
				'						{{item.text}}'+
				'					</label>'+
				'				{{/each}}'+
				'   		</div>'+
				'		{{else if status=="disabled"}}'+
				'   		<div class="control-input radio disabled">'+
				'				{{each list as item i}}'+
				'					<label class="radio-inline">'+
				'						<input type="radio" class="validatebox" name="{{name}}" value="{{item.key}}" data-type="{{type}}" data-quesId="{{id}}" data-innDeCode="{{innDeCode}}" data-deCode="{{deCode}}" data-dataUnit="{{dataUnit}}" data-validate="{{validate}}" data-attention="{{attention}}" disabled>'+
				'						{{item.text}}'+
				'					</label>'+
				'				{{/each}}'+
				'   		</div>'+
				'		{{/if}}'+
				'	</div>'+
				'</script>';
	}

	/**
	 * 赋值
	 */
	quest.setValue = function($dom,value){
		if( value ){
			$dom.each(function(i){
				if( value.quesValue == $(this).val() ){
					$(this).attr("checked","checked");
					return true; // 退出本次循环
				}
			});
		}
	}

	/**
	 * 获取value（保存时，获取每个dom对应的答案）
	 */
	quest.getValue = function($dom,name){
		var dom = $dom.parents(".qaCard").find("input[type='radio'][name='" + name + "']:checked");
		var value = {};
		if( dom.length > 0 ){
			value.quesValue = dom.val();
		}
		value.quesId = $dom.attr("data-quesId");
		value.deCode = $dom.attr("data-deCode");
		value.innDeCode = $dom.attr("data-innDeCode");
		var dataUnit = $dom.attr("data-dataUnit");
		if( dataUnit ) value.dataUnit = dataUnit;
		return value;
	}

	/**
	 * 事件函数
	 */
	quest.event = function(eventParams){
		$comm.cancelRadioChecked();
	}
    
	return quest;
});